package b_state.b_design_patten;

/**
 * Created by wug on 2016/6/14 0014.
 */
public class StateLucky implements State {
    WaterMachine waterMachine;

    public StateLucky(WaterMachine waterMachine) {
        this.waterMachine = waterMachine;
    }

    @Override
    public void workerPut() {

    }

    @Override
    public void insertMoney(int num) {

    }

    @Override
    public void pressSellBtn() {
        /**
         * 演示Luck时 需要解开各状态的注释
         */
        if (Math.random()*10<2 && waterMachine.getNum()>0 && waterMachine.getMoney()>=5) {
            waterMachine.setNum(waterMachine.getNum()-1);
            System.out.println("恭喜,再来一瓶!!剩余" + waterMachine.getNum() +"瓶水！");
        }
        waterMachine.setState(new StateSold(waterMachine));
        waterMachine.sell();
    }

    @Override
    public void refundRocker() {

    }

    /**
     * StateLucky 是一种内部的状态 用户行为是不会影响到它 所以其它方法不同实现了
     */
}
